import { createStore } from 'vuex'

let htmlArr = window.getComputedStyle(window.document.documentElement)
let fontSize = htmlArr['font-size'].replace(/px/g, '')

export default createStore({
  state: {
    // 请求地址头
    baseURL: /^(\w+\.)+[a-zA-Z]+$/.test(location.hostname) ? '' : '',
    // 手机状态栏高度
    height: 0,
    // html的字体大小
    fontSize: fontSize,
    // 按钮是否可点
    loading: false,
    // 控制是否显示loading加载框
    isLoading: true,
    // 登录信息
    token: localStorage.getItem('token') || ''
  },
  mutations: {
    setHeight(state, height) {
      state.height = height
    },
    setFontSize(state, fontSize) {
      state.fontSize = fontSize
    },
    setLoading(state, loading) {
      state.loading = loading
    },
    setIsLoading(state, isLoading) {
      state.isLoading = isLoading
    },
    setToken(state, token) {
      localStorage.setItem("token", token)
      state.token = token
    }
  },
  actions: {
    /**
     * 设置状态栏文字颜色
     * @param {String} color 可取值："dark"和"light"
     */
    SetStatusBarStyle(color) {
      if (window.plus) {
        plusReady()
      } else {
        document.addEventListener('plusready', plusReady, false)
      }
      function plusReady() {
        plus.navigator.setStatusBarStyle(color)
      }
    }
  },
  modules: {
  }
})
